// TOWN SCRIPT
//    Town 15: Bob's Cave
//      

// This is the special encounter script for this town.
// The states INIT_STATE, EXIT_STATE, and START_STATE have
// meanings that are described in the documentation. States you write
// yourself should be numbered from 10-100.

// flags:
// 15, 0 = magic mouth

begintownscript;

variables;

short choice, i;
string rmsg;

body;

beginstate INIT_STATE;
	turn_off_training(TRUE);
	set_crime_tolerance(1);

	if (get_flag(15, 0) == TRUE) {
		set_terrain(16, 18, 32);
	}
break;

beginstate EXIT_STATE;
break;

beginstate START_STATE;
break;

beginstate 10;
	if ((get_flag(51, 8) == TRUE) && (get_flag(15, 0) == FALSE)) {
		clear_buffer();
		i = get_ran(1, 1, 4);
		if (i == 2) {
			append_string("'Who is absorbent and yellow and porous is he?'");
		}
		else if (i == 3) {
			append_string("'Who asks if nautical nonsense be something you wish?'");
		}
		else if (i == 4) {
			append_string("'Who makes you want to flop on the deck and plop like a fish?'");
		}
		else {
			append_string("'Who lives in a pineapple under the sea?'");
		}
		get_buffer_text(rmsg);
		reset_dialog();
		add_dialog_str(0, "A mouth painted beside the gate starts moving and speaking as you get close.", 0);
		add_dialog_str(1, "The 'magic' mouth asks you a question.", 0);
		add_dialog_str(2, rmsg, 0);
		add_dialog_choice(0, "Give Answer");
		add_dialog_choice(1, "Leave");
		choice = run_dialog(TRUE);
		if (choice == 1) {
			get_text_response("Your response?");
			i = FALSE;
			check_text_response_match("BOB");
			if (got_text_match() > 0)
				i = TRUE;
			check_text_response_match("SPONGEBOB");
			if (got_text_match() > 0)
				i = TRUE;
			check_text_response_match("SPONGEBOB SQUAREPANTS");
			if (got_text_match() > 0)
				i = TRUE;
			if (i == TRUE) {
				set_flag(15, 0, TRUE);
				message_dialog("The magic mouth replies 'You have the correct answer'.",
					"The mouth fades from the wall and the gate opens.");
				play_sound(106);
				play_sound(99);
				set_terrain(16, 18, 32);
			}
			else {
				message_dialog("The magic mouth replies 'That is not correct'.",
					"It then turns back into a painted mouth on the wall.");
			}
		}
	}
	else {
		if (get_flag(51, 8) == FALSE) {
			message_dialog("There is a small mouth painted on the wall next to the gate.",
				"It glows slightly and is warm to the touch.");
		}
	}
break;

beginstate 11;
	if (get_flag(51, 7) == FALSE) {
		set_flag(51, 7, TRUE);
		message_dialog("Glimmering slightly amongst the bones is a wood-like cylinder.",
				"It's a piece of the staff!");
		change_spec_item(6, 1);
	}
	else {
		message_dialog("You sift through the bones, but find nothing else.", "");
	}
break;
